package de.tabuma.soapforms.soapproject.controller;

import de.tabuma.soapforms.*;
import de.tabuma.lib.tabumacontroller;
import de.tabuma.soap.WsdlFactory;
import de.tabuma.soap.logik.*;
import de.tabuma.soap.entity.wsdl.*;
import de.tabuma.soap.entity.soap.*;
import java.io.PrintWriter;
import java.util.*;
import java.util.logging.*;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.appengine.api.users.*;

/**
 *
 * @author alefen
 */
public class create1 extends tabumacontroller {

    private static final Logger log = Logger.getLogger(create1.class.getName());

    public create1(String servlet, Hashtable parameter) {
        super(servlet, parameter);
    }

    @Override
    public void navigate(ServletContext context, HttpServletRequest request, HttpServletResponse response, PrintWriter out) {
        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();

        if(request.getParameter(constants.cancel)!=null) {
            list list = new list(this.getServlet(), this.getParameter());
            list.navigate(context, request, response, out);
            return;
        }

        if(request.getParameter(constants.addSoapProject1)!=null) {

            String url = request.getParameter(constants.soapProjectUrl);
            log.warning(url);
            TDefinitions wsdlFile = WsdlFactory.loadWsdlUrl(url);
            log.warning(""+wsdlFile.getId());

            String customerId = request.getParameter(constants.customerId);

            List<String> messageList = new ArrayList<String>();
            List<Long> operationList1 = SoapFacade.getAllOperation(wsdlFile);
            for(int i=0;i<operationList1.size();i++) {
                TOperation operation = PMF.get(operationList1.get(i), new TOperation());
                messageList.add(operation.getName());
            }

            request.setAttribute(constants.soapProjectMethodList, messageList);
            request.setAttribute(constants.soapProjectUrl, url);
            request.setAttribute(constants.customerId, customerId);
            
            request.setAttribute(constants.addSoapProject1, "true");
            request.setAttribute(constants.soapProjectWsdlId, ""+wsdlFile.getId());
            return;
        }

    }
}
